package com.tcm.portal.web.controller;

import com.base.core.pager.PageBean;
import com.base.core.utils.R;
import com.search.service.SearchDoctorService;
import com.search.service.dto.SearchDoctorParam;
import com.tcm.doctor.domain.dto.RecommendDoctorDTO;
import com.tcm.doctor.service.DoctorService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RequestMapping("/portal/doctor")
@RestController
public class DoctorController {

    @DubboReference(version = "0.0.1-alpha", check = false, timeout = 3000)
    private DoctorService doctorService;

    @DubboReference(version = "0.0.1-alpha", check = false, timeout = 3000)
    private SearchDoctorService searchDoctorService;

    /**
     * 获取单条记录
     *
     * @param id
     * @return
     * @throws Exception
     */
    @GetMapping("/view")
    public R view(@RequestParam("id") Long id){
        return R.success(doctorService.findDoctorByUserId(id));
    }

    /**
     * 分页
     *
     * @param page
     * @param pagesize
     * @return
     */
    @GetMapping("/list/page")
    public R listDoctorPage(@RequestParam(defaultValue = "0") Long page,
                            @RequestParam(defaultValue = "10") Long pagesize) {
        PageBean listBean = doctorService.listDoctorPage(page, pagesize);
        return R.success(listBean);
    }

    /**
     * 分页
     *
     * @param page
     * @param pagesize
     * @return
     */
    @GetMapping("/list/search/page")
    public R listSearchDoctorPage(
                            @RequestParam(defaultValue = "") String name,
                            @RequestParam(defaultValue = "") String hospital,
                            @RequestParam(defaultValue = "") Long jobtitleId,
                            @RequestParam(defaultValue = "") String jobtitle,
                            @RequestParam(defaultValue = "") Integer cityId,
                            @RequestParam(defaultValue = "") Long departmentId,
                            @RequestParam(defaultValue = "") String department,
                            @RequestParam(defaultValue = "default") String sort,
                            @RequestParam(defaultValue = "1") int page,
                            @RequestParam(defaultValue = "10") int pagesize) {
        SearchDoctorParam searchDoctorParam = new SearchDoctorParam();
        searchDoctorParam.setName(name);
        searchDoctorParam.setHospital(hospital);
        searchDoctorParam.setJobtitle(jobtitle);
        searchDoctorParam.setDepartment(department);
        searchDoctorParam.setCityId(cityId);
        searchDoctorParam.setDepartmentId(departmentId);
        searchDoctorParam.setJobtitleId(jobtitleId);
        PageBean listBean = searchDoctorService.search(searchDoctorParam, page, pagesize,sort);
        return R.success(listBean);
    }

    /**
     * 根据医院获取医生列表
     * @param hospitalId
     * @return
     */
    @GetMapping("/list/recommend/doctor")
    public R listDoctorByHospital(@RequestParam("hospitalId") Long hospitalId){
        List<RecommendDoctorDTO> doctorDTOList = doctorService.listRecommendDoctor(hospitalId, 6);
        return R.success(doctorDTOList);
    }

}
